# 未绑定银行卡的用户发起结算，结算失败
import allure
from faker import Faker

from page_base.page_base import Base
# from page_element.el_A3mall import *
from page_element.roncoo_sett import *
from page_element.el_user import *
from page_element.el_settlement import *
from page_object.roncoo_login import RoncooLogin
from utils.mysql_util import PyMySql
from utils.timer import sleep
import logging


class SettUse(RoncooLogin):
    # def __init__(self):
    #     self.db = PyMySql()


    def use_sett(self):
        self.db = PyMySql()
        self.fk = Faker(locale='zh_CN')
    # 添加用户
        self.roncoo_login()
        name = self.fk.name()
        with allure.step(f"点击用户管理"):
            self.click(recnoo.recnoo_yggl)
            sleep(2)
        with allure.step(f"点击用户信息"):
            self.click(recnoo.recnoo_yyxx)
        with allure.step(f"点击添加按钮"):
            self.click(recnoo.recnoo_tjan)
        with allure.step(f"输入用户名称"):
            self.send_keys(recnoo.recnoo_yhmc, name)
            sleep(2)
        with allure.step(f"输入手机号"):
            self.send_keys(recnoo.recnoo_sjh, '18451121531')
            sleep(2)
        with allure.step(f"输入登录密码"):
            self.send_keys(recnoo.recnoo_dlmm, 'dlmm')
            sleep(2)
        with allure.step(f"点击提交按钮"):
            self.click(recnoo.recnoo_tijan)
            sleep(2)
        # with allure.step(f"断言"):
        #     dy = self.text(recnoo.recnoo_dy)
        #     assert '王蒙蒙' == dy
        #从数据库中获取用户编号
        # res = self.db.executeall(f'select user_no from rp_use_info where username = "王蒙蒙"')
        # userno = res[0][0]
        res = self.db.executeall(f"select user_no from rp_user_info WHERE user_name = '{name}';")
        userno = res[0][0]

        self.click(sett_pe.sett_ele)
        sleep(3)
        self.click(sett_pe.sett_ele_loc)
        sleep(2)
        self.click(sett_pe.recnoo_fqjsbtn)
        sleep(2)
        self.click(recnoo.recnoo_sstb)
        sleep(1)
        self.click(recnoo.recnoo_xz)
        sleep(1)
        # 点击获取可结算余额
        self.click(sett_pe.getsett_loc)
        # 可结算余额--输入
        self.send_keys(sett_pe.setamount_loc, '0')
        # 点击提交按钮
        self.click(sett_pe.submit_loc)
        # 断言操作成功
        dy = self.text(sett_pe.sucess_loc)
        assert '成功' in dy, '发起结算成功'
        sleep(5)











